package com.jiankangjin.appspos.util;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.jiankangjin.httpclient.PropertiesLoader;

/**
 */
public class ResourceMap {
	private static final transient Log log = LogFactory
			.getLog(ResourceMap.class);

	public static String get(String key) {
		return resourceMap.get(key);
	}
	public static String[] getArray(String key) {
        String val = resourceMap.get(key);
		log.debug(">>>key=" + key + ">>>value=" + val);
        if (val == null || "".equals(val)) return null;
		return val.split(",");
	}

	private static Map<String, String> resourceMap = new HashMap<>();

	static {
		InputStream inputStream = PropertiesLoader.class.getClassLoader()
				.getResourceAsStream("resouces.properties");
		Properties pops = new Properties();
		try {
			pops.load(inputStream);
			Set<Entry<Object, Object>> set = pops.entrySet();
			Iterator<Map.Entry<Object, Object>> it = set.iterator();

            for (Entry<Object, Object> e : pops.entrySet())
                resourceMap.put((String)e.getKey(), (String)e.getValue());

		} catch (Exception e) {
			log.error("加载resouces.properties失败");
		}
	}

}
